package com.tengju.motivation.infrastructure.repository.performance.convert;


import com.tengju.motivation.domain.model.performance.*;
import com.tengju.motivation.domain.shared.IdObject;
import com.tengju.motivation.infrastructure.persistence.mybatis.dataobject.PerformanceObjectiveDO;

import java.util.Optional;

public class PerformanceObjectiveConvert {

    public static PerformanceObjective convert(PerformanceObjectiveDO performanceObjectiveDO) {
        if (null == performanceObjectiveDO) {
            return null;
        }
        return new PerformanceObjective(
                new PerformanceObjectiveId(performanceObjectiveDO.getPerformanceObjectiveId()),
                new PerformanceObjectiveObjectId(performanceObjectiveDO.getObjectId()),
                PerformanceObjectiveTypeEnum.form(performanceObjectiveDO.getType()),
                performanceObjectiveDO.getKey(),
                performanceObjectiveDO.getName(),
                performanceObjectiveDO.getDesc(),
                performanceObjectiveDO.getValue(),
                performanceObjectiveDO.getStartTime(),
                performanceObjectiveDO.getEndTime(),
                PerformanceObjectiveStatusEnum.form(performanceObjectiveDO.getStatus()),
                performanceObjectiveDO.getCreateBy(), performanceObjectiveDO.getUpdateBy(),
                performanceObjectiveDO.getCreateTime(), performanceObjectiveDO.getUpdateTime());
    }

    public static PerformanceObjectiveDO convert(PerformanceObjective performanceObjective) {
        return new PerformanceObjectiveDO(
                Optional.ofNullable(performanceObjective.getPerformanceObjectiveId()).map(IdObject::getValue).orElse(null),
                Optional.ofNullable(performanceObjective.getObjectId()).map(IdObject::getValue).orElse(null),
                Optional.ofNullable(performanceObjective.getType()).map(PerformanceObjectiveTypeEnum::getCode).orElse(null),
                performanceObjective.getKey(),
                performanceObjective.getName(),
                performanceObjective.getDesc(),
                performanceObjective.getValue(),
                performanceObjective.getStartTime(),
                performanceObjective.getEndTime(),
                Optional.ofNullable(performanceObjective.getStatus()).map(PerformanceObjectiveStatusEnum::getCode).orElse(null),
                performanceObjective.getCreateBy(), performanceObjective.getUpdateBy(),
                performanceObjective.getCreateTime(), performanceObjective.getUpdateTime());
    }
}
